"main" can be valid name for binary again, improve test
authorMartin Sehnoutka <msehnout@redhat.com>
Wed, 28 Jun 2017 12:02:25 +0000 (14:02 +0200)
committerMartin Sehnoutka <msehnout@redhat.com>
Wed, 28 Jun 2017 12:02:25 +0000 (14:02 +0200)
src/cargo/util/toml.rs
tests/build.rs

index b70b102f72268324baf8f9692d3fb5f7a410fc5f..d1793cfc9386c0c5c63c42982208eceb8cf56c5d 100644 (file)
@@ -531,12 +531,8 @@ fn inferred_bin_targets(name: &str, layout: &Layout) -> Vec<TomlTarget> {
                     // if the path ends with main.rs it is probably a directory, but it can also be
                     // a file directly inside src/bin
                     if parent.ends_with("src/bin") {
-                        // This would always return name "main"
-                        // Fixme: Is this what we want? based on what @matklad said, I don't think so
-                        // bin.file_stem().and_then(|s| s.to_str()).map(|f| f.to_string())
-
-                        // This seems to be the right solution based on the inferred_bin_paths function
-                        Some(name.to_string())
+                        // This will always return name "main"
+                        bin.file_stem().and_then(|s| s.to_str()).map(|f| f.to_string())
                     } else {
                         parent.file_stem().and_then(|s| s.to_str()).map(|f| f.to_string())
                     }
index bbc1ca1b167cf339b1f1e8797f174e35aaeece68..b5ab977cc5e522dd454131447d99b5573c7d6e4e 100644 (file)
@@ -3310,8 +3310,11 @@ fn dir_and_file_with_same_name_in_bin() {
         .file("src/bin/foo.rs", "fn main() {}")
         .file("src/bin/foo/main.rs", "fn main() {}");
 
-    // TODO: This should output the error from toml.rs:756
-    assert_that(p.cargo_process("build"), execs().with_status(101));
+    assert_that(p.cargo_process("build"), 
+                execs().with_status(101)
+                       .with_stderr_contains("\
+[..]found duplicate binary name foo, but all binary targets must have a unique name[..]
+"));
 }
 
 #[test]